﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace AnaxibiaStudios.Smug.Internal
{
  public class EventInfoEx : MemberInfoEx<EventInfo>
  {
    public MethodInfoEx Add { get; protected set; }
    public MethodInfoEx Remove { get; protected set; }
    public MethodInfoEx Invoke { get; protected set; }

    public EventInfoEx(MemberCollection parent, EventInfo ev)
      : base(parent, ev)
    {
      Add = MemberInfoEx.Wrap(parent, ev.GetAddMethod(true));
      Remove = MemberInfoEx.Wrap(parent, ev.GetRemoveMethod(true));
      Invoke = MemberInfoEx.Wrap(parent, ev.EventHandlerType.GetMethod(SourceBuilder.Invoke, Constants.Flags)) as MethodInfoEx;

      SetModifiers(Add.Info);
      SetParameters(Invoke.ReturnType, Invoke.Info.GetParameters());
    }

    public override PreexistingType Hit(MemberInfoEx ex)
    {
      bool partial = this.Name == ex.Name;
      var eex = ex as EventInfoEx;

      bool exact =
        partial &&
        ex.MemberType == MemberTypes.Event
        &&
        (
          MethodInfoEx.Match(eex.Add, Add, true) &&
          MethodInfoEx.Match(eex.Remove, Remove, true)
        );

      if (exact)
        return PreexistingType.Exact;
      else if (partial)
        return PreexistingType.Conflicting;
      else
        return PreexistingType.New;
    }

    public override string BuildBody()
    {
      return string.Empty;
    }

    protected override bool MatchesNonOverload(MemberInfoEx that)
    {
      throw new NotImplementedException();
    }

    protected override bool IsOverloadable()
    {
      throw new NotImplementedException();
    }
  }
}
